# -*- coding:UTF-8 -*-

# author:user
# contact: test@test.com
# datetime:2021/11/22 9:56
# software: PyCharm

"""
文件说明：
    
"""
from rasa.shared.nlu.training_data.loading import load_data
from rasa.shared.importers.importer import TrainingDataImporter
from rasa.nlu.config import RasaNLUModelConfig
from rasa.nlu.model import Trainer
from rasa.shared.utils.io import read_config_file
from rasa.nlu import config
from rasa.core.agent import Agent
from rasa.core.policies.memoization import MemoizationPolicy
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.core.policies.ted_policy import TEDPolicy


# 训练模型
def train():
    # 示例数据
    training_data = load_data('./data/nlu.yml')
    # pipeline配置
    configs = read_config_file("./config.yml")
    # trainer = Trainer(config.load("sample_configs/museum_config.json"))
    trainer = Trainer(config.load(configs))
    trainer.train(training_data)
    model_directory = trainer.persist('./models/')
    print(model_directory)
    predict(model_directory)

    # 识别意图


def predict(model_directory):
    from rasa.nlu.model import Metadata, Interpreter

    interpreter = Interpreter.load(model_directory)
    # 使用加载的interpreter处理文本
    print(interpreter.parse(u"这里有什么好看的展览"))


if __name__ == '__main__':
    train()

